package functional.stream;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 *
 * @author Liu Yicong
 * @date 2025/10/8
 */
public class Test {

	public static void main(String[] args) {
		Student stu1 = new Student(1, "a", 21);
		Student stu2 = new Student(2, "b", 22);
		Student stu3 = new Student(3, "c", 33);
		Student stu4 = new Student(4, "d", 21);
		List<Student> list = Arrays.asList(stu1, stu2, stu3, stu4);
		Map<Integer, List<Student>> mapByAge = list.stream().
				collect(Collectors.groupingBy(Student::getAge));
		System.out.println(mapByAge);

		Map<Integer, Long> mapCount = list.stream().
				collect(Collectors.groupingBy(Student::getAge, Collectors.counting()));
		System.out.println(mapCount);
	}
}
